﻿
var IsCheck = true;
var IsEmail =true;
$(document).ready(function () {
    ClearMsg("Email");
    ClearMsg("NickName");
    ClearMsg("Pwd");
    ClearMsg("PwdOk");
    ClearMsg("TxtCode");
    


});

function CheckEmail() {

    var result = GetAjax("/UserAPI/CheckEmail", "Email=" + $("#Email").val()).responseText;
  
    if (result == "1") {
        IsEmail = false;
        ShowMsg("Email", "邮箱已被注册");
       
    }
    else
    { IsEmail = true; }
}

function CheckNickName() {
    var result = GetAjax("/UserAPI/CheckNickName", "NickName=" +$("#NickName").val()).responseText;

    if (result == "1") {
        IsCheck = false;
       ShowMsg("NickName", "昵称已被占用,请选择其他呢称");
    }
   else
       { IsCheck =true;
       }
}

function Img() {
    $("#imgcode").attr("src", '/ashx/gif.ashx?'+new Date()); 
   
}

function Create() {

    var Email = $("#Email").val();
    var NickName = $("#NickName").val();
    var pwd = $("#Pwd").val();
    var Pwdok = $("#PwdOk").val();
    var Code = $("#TxtCode").val();
  
    
    var EmailIsTrueFlase = (/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);

    if (!EmailIsTrueFlase.test(Email)) {
        ShowMsg("Email", "邮箱不正确");
        return;
    }
    if (pwd.length < 6) {
        ShowMsg("Pwd", "密码不能少于六位数");
        return;
    }
    if(NickName.length<6) {
        ShowMsg("NickName", "昵称只能3~20位，每个中文字算2位字符");
        return;
    }
    if (!IsEmail) {
        ShowMsg("Email", "邮箱已被注册");
        return;
    }
    if (!IsCheck) {
        ShowMsg("NickName", "昵称已被占用,请选择其他呢称");
        return;
    }
   
    if (pwd!= Pwdok)
     {
         ShowMsg("PwdOk", "密码不一致");
        return;
    }
    if(Code=="") {
        ShowMsg("TxtCode", "验证码不能为空");
        return;
    }
    
   

      
 var url=string.Format("Email={0}&NickName={1}&Pwd={2}&Code={3}",Email,NickName,pwd,Code);

 $.ajax({
     url: "/UserAPI/Create?" + url,
     type: "post",

     dataType: "json",
     contentType: "application/json; charset=utf8",
     success: function (data) {
         if (data.isSuccess) {
             self.location = "/User/CreateMsg?Email=" + Email;
         }
         else {
             if (data.Message == "验证码不正确") {

                 ShowMsg("TxtCode", data.Message);
             }
             else {
                 alert(data.Message);
             }
         }



     }
 });

    
  
}